package com.msg;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Hashtable;

import com.ue.Config;
import com.ue.util.StringHelper;

/**
 * 
 * <获取消息模板>
 * <功能详细描述>
 * 
 * @author  huanglz
 * @version  [版本号, 2012-3-15]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class TemplateManager {
	private static Hashtable<String, String> m_dicTemplate = new Hashtable<String, String>();

	public static String get(String strTemplateName) {
		String strTemplate = "";
		if (StringHelper.isNotNullAndEmpty(strTemplateName)) {
			if (m_dicTemplate.containsKey(strTemplateName)) {
				strTemplate = m_dicTemplate.get(strTemplateName);
			} else {
				String strTemplatePath = Config.ApplicationPath + "template/"
						+ strTemplateName + ".tp";
				// LogManager.debugWrite(strTemplatePath);
				File file = new File(strTemplatePath);
				if (file.exists()) {
					char data[] = new char[1024];
					int intLength = 0;
					BufferedReader br;
					try {
						br = new BufferedReader(new InputStreamReader(
								new FileInputStream(file), "utf-8"));
						while ((intLength = br.read(data)) > 0)
							strTemplate += new String(data, 0, intLength);
						m_dicTemplate.put(strTemplateName, strTemplate);
						try {
							br.close();
						} catch (IOException e) {
							e.printStackTrace();
						}
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}
		return strTemplate;
	}
}
